package com.shelpe.services.sinbad.service.simbaproxy;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sinbad.service.simbaproxy.AuthClient.AuthClientFallback;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@FeignClient(name="${feign.authserver.name}", url="${feign.authserver.url}", fallback=AuthClientFallback.class)
public interface AuthClient {
    
	
	@RequestMapping(method = RequestMethod.GET, value = "/taobao/users/{id}/accessTokens")
	UserToken findSessionKeyByID(@PathVariable("id")long tanentID);
	
	
	@Data
	@JsonInclude(Include.NON_NULL)
	public static class UserToken{
		public final static String TYPE_PROXY = "proxy";
		public final static String TYPE_PURCHASE = "purchase";
		
		@JsonProperty("access_token")
		private String accessToken;
		private String type;
		private boolean expired;
	}
	
	@Slf4j
	@Service
	public static class AuthClientFallback implements AuthClient{

		@Override
		public UserToken findSessionKeyByID(long tanentID) {
			log.error("fallback findSessionKeyByID: {}", tanentID);
			return new UserToken();
		}
		
	}

}